package com.datatrans.example;

import com.datatrans.config.TransferConfig;
import com.datatrans.service.DatabaseService;
import com.datatrans.exception.TransferException;

import java.sql.Connection;

/**
 * 数据库连接测试类
 * 用于验证数据库驱动是否正确加载以及连接是否正常工作
 */
public class DatabaseConnectionTest {
    
    public static void main(String[] args) {
        // 检查命令行参数
        if (args.length > 0 && ("--help".equals(args[0]) || "-h".equals(args[0]))) {
            printHelp();
            return;
        }
        
        // 进行数据库驱动测试
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("MySQL驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.out.println("MySQL驱动加载失败: " + e.getMessage());
        }
        
        try {
            Class.forName("org.postgresql.Driver");
            System.out.println("PostgreSQL驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.out.println("PostgreSQL驱动加载失败: " + e.getMessage());
        }
        
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            System.out.println("MSSQL驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.out.println("MSSQL驱动加载失败: " + e.getMessage());
        }
        
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("Oracle驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.out.println("Oracle驱动加载失败: " + e.getMessage());
        }
        
        // 测试DatabaseService是否能正确工作
        testDatabaseService();
        
        System.out.println("数据库驱动测试完成");
    }
    
    private static void printHelp() {
        System.out.println("数据库驱动测试工具");
        System.out.println("使用方法:");
        System.out.println("  java -cp data-transfer-1.0-SNAPSHOT-jar-with-dependencies.jar com.datatrans.example.DatabaseConnectionTest [选项]");
        System.out.println("");
        System.out.println("选项:");
        System.out.println("  -h, --help\t显示帮助信息");
        System.out.println("");
        System.out.println("说明:");
        System.out.println("  此工具用于测试MySQL、PostgreSQL、MSSQL和Oracle驱动是否能正常加载");
    }
    
    private static void testDatabaseService() {
        try {
            DatabaseService service = new DatabaseService();
            System.out.println("DatabaseService创建成功");
        } catch (Exception e) {
            System.out.println("DatabaseService创建失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}